//
//  ZYXStudyDetHeaderView.m
//  RuiBeiKang
//
//  Created by iOS开发1 on 2019/1/11.
//  Copyright © 2019年 JW. All rights reserved.
//

#import "ZYXStudyDetHeaderView.h"

@implementation ZYXStudyDetHeaderView
-(void)awakeFromNib{
    [super awakeFromNib];
    self.webView.delegate = self;
  
    [self.webView.scrollView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil];

}
-(void)setModel:(ZYXStudyModel *)model{
    _model = model;
    self.titleLabel.text = model.title;
    
    self.timeLabel.text = model.create_time;

    
//    NSString *urlstr = [NSString stringWithFormat:@"%@?news_id=%@",kInterfaceAllUrl(@"/index.php/mobile/user_port/all"),model.uid];
    NSString *urlstr = model.content_url;
    NSURL *locationURL = [NSURL URLWithString:urlstr];
    
    // 3.创建Request
    NSURLRequest *request =[NSURLRequest requestWithURL:locationURL];
    // 4.加载网页
    [self.webView loadRequest:request];
  
    self.countNum.text = [NSString stringWithFormat:@"%@条评论",model.count];
    
}
-(void)webViewDidFinishLoad:(UIWebView *)webView{
    
      self.webView.scrollView.scrollEnabled = NO;
    
    CGSize fittingSize  =  self.webView.scrollView.contentSize;
    NSLog(@"%f",fittingSize.height);
    CGFloat webHeight = fittingSize.height +70;
    [[NSNotificationCenter defaultCenter] postNotificationName:@"ceshigaodu" object:[NSString stringWithFormat:@"%f",webHeight] ];

    
}
#pragma mark - KVO
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if ([keyPath isEqualToString:@"contentSize"]) {
        
        CGPoint point = [change[@"new"] CGPointValue];
        
        CGFloat height = point.y;
        NSLog(@"point.y---%f",height);
        
        CGSize fittingSize = [self.webView sizeThatFits:CGSizeZero];
        
        CGFloat webHeight = fittingSize.height;
        
        self.webViewHeight.constant = webHeight;
      

    }
}
@end
